program List2;


{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement = ^element;
  element = record
    value : Integer;
    next : pelement;
  end;


var
  n, i, a: integer;
  fin : textfile;
  head : pelement;
  flag : boolean;


procedure AddToBegin (var head : pelement; num : integer);
  var tmp : pelement;
  begin
    tmp := head;
    New (head);
    head^.value := num;
    head^.next := tmp;
  end;

function DeleteFromBegin (var head : pelement):integer;
  var tmp : pelement;
  begin
      if (head <> nil) then
      begin
          tmp := head^.next;
          DeleteFromBegin := head^.value;
          Dispose (head);
          head := tmp;
      end;
  end;

procedure PrintList (head : pelement);
  var current : pelement;
  begin
    current := head;
    while (current <> nil) do
    begin
        Writeln (current^.value);
        current := current^.next;
    end;
  end;

procedure AddToEnd (head : pelement; num : integer);
  var current : pelement;
  begin
    if (head <> nil) then
    begin
      current := head;
      while (current^.next <> nil) do
      begin
        current := current^.next;
     end;
     new (current^.next);
     current^.next.next := nil;
     current^.next^.value := num;
    end else
    begin
      AddToBegin(head, num);
    end;
    end;

procedure DeleteFromEnd (var head : pelement);
begin
  if (head<>nil) then
    if (head^.next=nil) then
      DeleteFromBegin(head)
    else
      DeleteFromEnd(head^.next);
end;

begin
  assignfile (fin, 'input1.txt');
  Reset (fin);
  Read(fin, n);
  for i := 0 to n-1 do
  begin
    read (fin, a);
    AddToBegin(head, a);
  end;
  flag:=false;

  for i:= 0 to 4 do
  begin
    if (head<>nil) then
    begin
      DeleteFromBegin(head);
    end else begin
      writeln ('Error!');
      flag:=true;
      break;
    end;
  end;

  for i := 0 to 4 do
  begin
    if (head<>nil) then
    begin
      DeleteFromEnd(head);
    end else begin
      if (flag) then
        break;
      if (flag<>true) then
      begin
        writeln ('Error!');
        flag:=true;
        break;
      end;
    end;
  end;

  for i := 0 to n-1 do
  begin
    if (head=nil) or (head^.next=nil) or (head^.next^.next=nil) then
    begin
      if (flag) then
        break;
      if (flag<>false) then
      begin
        writeln('Error!');
        flag:=true;
        break;
      end;
    end;
    if (head^.next^.next^.next<>nil) then
    begin
      DeleteFromBegin(head^.next^.next^.next);
      break;
    end;
    head:=head^.next;
  end;

  if (flag=false) then
    PrintList(head);

  CloseFile (fin);
  Readln;
end.

